/// @tags:
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 100;

char l[maxn + 1], r[maxn + 1], tmp[maxn + 1];

int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> tmp >> r;
    int n = strlen(r);
    memset(l, '0', sizeof(l));
    memcpy(l + n - strlen(tmp), tmp, strlen(tmp));

    bool flag = false;
    for (int i = 0; i < n; ++i) {
      if (r[i] > l[i]) {
        cout << 9 * (n - i - 1) + (r[i] - l[i]) << endl;
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << 0 << endl;
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Maximum Strength.in", "r", stdin);
  freopen("B. Maximum Strength.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
